package xyz.wbsite.dbtool.javafx.po;

import javafx.beans.property.SimpleStringProperty;
import xyz.wbsite.dbtool.javafx.annotation.Property;

import java.util.ArrayList;
import java.util.List;

public class Module {
    public Module() {

    }

    public Module(String name) {
        setName(name);
    }

    @Property("name")
    private SimpleStringProperty name = new SimpleStringProperty();
    @Property("note")
    private String note;
    @Property("prefix")
    private String modulePrefix;
    @Property("needGenerate")
    private boolean needGenerate;

    private String projectName;
    private String projectBasePackage;
    private String projectAuthor;

    private List<Table> tables = new ArrayList();

    public String getName() {
        return name.get();
    }

    public SimpleStringProperty nameProperty() {
        return name;
    }

    public void setName(String name) {
        this.name.set(name);
    }

    public boolean putTable(Table table) {
        if (tables == null) {
            tables = new ArrayList<Table>();
        }
        tables.add(table);
        return true;
    }

    public boolean hasHtml() {
        for (Table table : tables) {
            if (table.isPage()) return true;
        }
        return false;
    }

    public List<Table> getTables() {
        return tables;
    }

    public void setTables(List<Table> tables) {
        this.tables = tables;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getModulePrefix() {
        return modulePrefix;
    }

    public void setModulePrefix(String modulePrefix) {
        this.modulePrefix = modulePrefix != null ? modulePrefix : "";
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public String getProjectBasePackage() {
        return projectBasePackage;
    }

    public void setProjectBasePackage(String projectBasePackage) {
        this.projectBasePackage = projectBasePackage;
    }

    public String getProjectAuthor() {
        return projectAuthor;
    }

    public void setProjectAuthor(String projectAuthor) {
        this.projectAuthor = projectAuthor;
    }

    public boolean getNeedGenerate() {
        return needGenerate;
    }

    public void setNeedGenerate(boolean needGenerate) {
        this.needGenerate = needGenerate;
    }
}
